package com.jintoufs.service.baseinfo.impl;

import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.baseinfo.CustomerDAO;
import com.jintoufs.domain.baseinfo.Customer;
import com.jintoufs.logAnnotation.SystemServiceLog;
import com.jintoufs.service.baseinfo.CustomerService;
import com.jintoufs.service.user.PasswordHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/1 0001.
 */
@Service
public class CutomerServiceImpl implements CustomerService {

    @Resource
    private CustomerDAO customerDAO;
    @Autowired
    private PasswordHelper passwordHelper;

    @Override
    public List<Customer> getByFilter(QueryFilters filters) {
        List<Customer> result = customerDAO.getByFilter(filters);
        return result;
    }


    @Override
    public List<Customer> queryByParams(Map<String, Object> params) {
        return customerDAO.queryByParams(params);
    }

    @Override
    @SystemServiceLog(description = "新增客户")
    public Customer add(Customer customer) {
        customerDAO.insert(customer);
        return customer;
    }

    @Override
    @SystemServiceLog(description = "修改客户")
    public void update(Customer customer) {
        customerDAO.update(customer);
    }

    @Override
    @SystemServiceLog(description = "删除客户")
    public void delete(Long id) {
        customerDAO.delete(id);
    }

    @Override
    public Customer getById(Long id) {
        return customerDAO.queryByPrimaryKey(id);
    }

    @Override
    public Customer initPassword(Long id) {

        Customer customer=customerDAO.queryByPrimaryKey(id);
        customer.setPassword("666666");
        passwordHelper.encryptPassword(customer);
        customerDAO.update(customer);
        return null;
    }
}
